package com.itbbfx.mapper;

import com.itbbfx.entity.Role;
import com.itbbfx.entity.RoleMenu;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface RoleMapper extends Mapper<Role> {
    @Select("select * from sys_role")
    List<Role> initUserRole();

    List<Role> selectAllRole(@Param("role") Role role);

    @Select("select count(1) from sys_role where rolename=#{rolename}")
    int queryRoleName(@Param("rolename") String rolename);

    @Insert("insert into sys_role(rolename,roledesc,available)" +
            "values(#{role.rolename},#{role.roledesc},#{role.available})")
    int addRole(@Param("role") Role role);

    @Update("update sys_role set rolename=#{role.rolename},roledesc=#{role.roledesc}," +
            "available=#{role.available} where roleid=#{role.roleid}")
    int updateRole(@Param("role") Role role);

    @Delete("delete from sys_role_user where roleid=#{roleid}")
    int deleteUserRole(@Param("roleid") int roleid);

    @Delete("delete from sys_role where roleid=#{roleid}")
    int deleteRole(@Param("roleid") int roleid);

    @Select("select count(rid) from sys_role_menu where rid=#{roleid}")
    int queryRoleMenu(@Param("roleid") Integer roleid);

    @Delete("delete from sys_role_menu where rid=#{roleid}")
    int deleteRoleMenu(@Param("roleid") Integer roleid);

    int saveRoleMenu(@Param("roleMenu") RoleMenu roleMenu);

    @Select("select mid from sys_role_menu where rid=#{roleid}")
    List<Integer> initRoleMenu(@Param("roleid") int roleid);

    @Select("select count(rid) from sys_role_user where rid=#{roleid}")
    int queryUserRole(@Param("roleid") int roleid);
}